<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="/static/js/head.js"></script>
<link rel="stylesheet" type="text/css" href="/static/css/contractCollect.css" />
</head> 
<body>
<div align="center" style="width:100%">
	<fieldset>
		<form id="Form">
			<table class="tableForm">
				<tr>
					<td class="formLeft">开始时间:</td>
					<td class="formRight">
						<input class="easyui-datebox" data-options="required:true" name="endTimeBegin" id="endTimeBegin">
					</td>
				</tr>
				<tr>
					<td class="formLeft">结束时间:</td>
					<td class="formRight">
						<input class="easyui-datebox" data-options=" " name="endTimeEnd" id="endTimeEnd"  ></input>
					</td>
				</tr>
				<tr>
					<td class="formLeft">甲方名称:</td>
					<td class="formRight">
						<select class="easyui-combobox" name="firstPartyName" id="firstPartyName" placeholder="甲方名称"  style="width:235px;">
						    <option value="移动">移动</option>
						    <option value="联通">联通</option>
						    <option value="电信">电信</option>
						    <option value="铁塔">铁塔</option>
						    <option value="省通建">省通建</option>
						    <option value="广电">广电</option>
						    <option value="其他">其他</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="formLeft">小项状态:</td>
					<td class="formRight">
						<select id="endStatus" class="easyui-combobox" name="endStatus" style="width:235px;">
						    <option value="true" selected="selected">已完成</option>
						    <option value="false">未完成</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="formLeft">合作单位:</td>
					<td class="formRight">
						<input class="easyui-validatebox" name="cooperator" id="cooperator"></input>
					</td>
				</tr>
				<tr>
					<td colspan="2" style="text-align: center;">
						<p><a href="#" class="easyui-linkbutton c1" style="width:100px" id="countAll">统计</a></p>
					</td>
				</tr>
				<tr>
					<td class="formLeft">小项数量:</td>
					<td class="formRight" id="count"></td>
				</tr>
				<tr>
					<td class="formLeft">总收入:</td>
					<td class="formRight"id="cashedAmount"></td>
				</tr>
				<tr>
					<td class="formLeft">支出金额:</td>
					<td class="formRight"id="payedAmount"></td>
				</tr>
				<tr>
					<td class="formLeft">未支付尾款:</td>
					<td class="formRight"id="balanceAmount"></td>
				</tr>
				<tr>
					<td class="formLeft">实时盈亏（不含未支付尾款）:</td>
					<td class="formRight"id="realTimeAmount"></td>
				</tr>
				<tr>
					<td class="formLeft">实际盈亏（包含未支付尾款）:</td>
					<td class="formRight"id="actualAmount"></td>
				</tr>
				<tr>
					<td colspan="2" style="text-align: center;">
						<p><a href="#" class="easyui-linkbutton c1" style="width:100px" id="countDetail">查看明细</a></p>
					</td>
				</tr>
			</table>
		</form>
	</fieldset>
</div>
</body>
</html>
<script>
$(function(){
	$.ajaxSetup({crossDomain: true, xhrFields: {withCredentials: true}});
	$('#countAll').click(function(){
			if($("#endTimeBegin").val()==null ||$("#endTimeBegin").val()==""){
				$.messager.alert("提示","开始时间不能为空!");
				return;
			}
			if($('#endStatus').combobox('getValue')=="true"){
				if($("#endTimeEnd").val()==null ||$("#endTimeEnd").val()==""){
					$.messager.alert("提示","结束时间不能为空!");
					return;
				}
			}else{
				if($("#endTimeEnd").val()!=null&&$("#endTimeEnd").val().length>0){
					$.messager.alert("提示","查询未结束小项时，不能输入结束时间!");
					return;
				}
			}
			$.ajax({
				url:getHost() + '/small_item/summary_by_time_range',
				type:'POST',
				data:JSON.stringify({
					createTimeBegin : $('#endStatus').combobox('getValue')=="true"?"":$('#endTimeBegin').datebox('getValue'),
					endTimeBegin : $('#endStatus').combobox('getValue')=="true"?$('#endTimeBegin').datebox('getValue'):"",
					endTimeEnd : $("#endTimeEnd").val(),
					firstPartyName : $('#firstPartyName').combobox('getValue').trim()==""?null:$('#firstPartyName').combobox('getValue'),
					cooperator : $("#cooperator").val(),
					end : $('#endStatus').combobox('getValue'),
				}),
				async : false,
				dataType : "json",
				contentType: 'application/json;charset=UTF-8',
				error:function(){
					$.messager.alert("提示","数据操作存在异常!");
				},
				success:function(data){
					if(data.code==200){
						$("#cashedAmount").html(data.data.item.cashedAmount);
						$("#payedAmount").html(data.data.item.payedAmount);
						$("#balanceAmount").html(data.data.item.balanceAmount);
						$("#realTimeAmount").html(data.data.item.realTimeAmount);
						$("#actualAmount").html(data.data.item.actualAmount);
						$("#count").html(data.data.item.count);
					}else{
						$.messager.alert("提示",data.message);
					}
				}
			});
	});
	$('#countDetail').click(function(){
		sessionStorage.setItem('createTimeBegin',$('#endStatus').combobox('getValue')=="true"?"":$('#endTimeBegin').datebox('getValue'));
		sessionStorage.setItem('endTimeBegin',$('#endStatus').combobox('getValue')=="true"?$('#endTimeBegin').datebox('getValue'):"");
		sessionStorage.setItem('endTimeEnd',$("#endTimeEnd").val());
		sessionStorage.setItem('firstPartyName',$('#firstPartyName').combobox('getValue'));
		sessionStorage.setItem('end',$('#endStatus').combobox('getValue'));
		sessionStorage.setItem('cooperator',$("#cooperator").val());
		parent.addTab('汇总明细',  "/countDetail.html")
	});
	
	$("#endTimeEnd").next("span").bind("click", function () {
		if($('#endStatus').combobox('getValue')=="false"){
			$.messager.alert("提示","查询未结束小项时，不能输入结束时间!");
			$('#endTimeEnd').datebox('setValue',"")
			return;
		}
	})
	$("#endStatus").combobox({
        onChange:function(n,o){ //这里的参数n是select改变后的value,o是改变前的value 
    		if(n=="false"){
    			$('#endTimeEnd').datebox('setValue',"");
    			$('#endTimeEnd').datebox('readonly');
    		}else if(n=="true"){
    			$('#endTimeEnd').datebox('readonly',false);
    		}
        }
    });
});
</script>